home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / TrackWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  59.1 KB  |  1,768 lines  |  [TEXT/KAHL]

  1. /* TrackWindow.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "TrackWindow.h"
  31. #include "Scroll.h"
  32. #include "MainWindowStuff.h"
  33. #include "TrackObject.h"
  34. #include "TrackList.h"
  35. #include "WindowDispatcher.h"
  36. #include "Memory.h"
  37. #include "IconButton.h"
  38. #include "NoteButtonImages.h"
  39. #include "GrowIcon.h"
  40. #include "Main.h"
  41. #include "TrackView.h"
  42. #include "NoteObject.h"
  43. #include "Array.h"
  44. #include "TrackAttributeDialog.h"
  45. #include "CommandChooser.h"
  46. #include "DataMunging.h"
  47. #include "GlobalWindowMenuList.h"
  48. #include "SampleDeviceOutput.h"
  49. #include "Alert.h"
  50. #include "NumberDialog.h"
  51. #include "DiskFileOutput.h"
  52.  
  53.  
  54. #define WINDOWXSIZE (500)
  55. #define WINDOWYSIZE (290)
  56.  
  57. #define BUTTONSXSTART (-1)
  58. #define BUTTONSY (-1)
  59. #define BUTTONWIDTH (24)
  60. #define BUTTONHEIGHT (24)
  61. #define BUTTONINCREMENT (BUTTONWIDTH - 1)
  62. #define BUTTONEXOINCREMENT (3)
  63.  
  64. #define HSCROLLX (-1)
  65. #define HSCROLLY(WinHeight) ((WinHeight) - 16 + 1)
  66. #define HSCROLLWIDTH(WinWidth) ((WinWidth) + 2 - 15)
  67.  
  68. #define VSCROLLX(WinWidth) ((WinWidth) - 16 + 1)
  69. #define VSCROLLY (BUTTONSY + BUTTONHEIGHT - 1)
  70. #define VSCROLLHEIGHT(WinHeight) ((WinHeight) - VSCROLLY - 15 + 1)
  71.  
  72. #define TRACKVIEWX (0)
  73. #define TRACKVIEWY (BUTTONSY + BUTTONHEIGHT)
  74. #define TRACKVIEWWIDTH(WindowWidth) ((WindowWidth) - 15)
  75. #define TRACKVIEWHEIGHT(WindowHeight) ((WindowHeight) - 15 - TRACKVIEWY)
  76.  
  77.  
  78. struct TrackWindowRec
  79.     {
  80.         MainWindowRec*                    MainWindow;
  81.         TrackObjectRec*                    TrackObject;
  82.         TrackListRec*                        TrackList;
  83.  
  84.         /* NoteState contains the flags for a note.  If eCommandFlag bit is set, then */
  85.         /* all of the other bits are disregarded and clicking will ask for a command. */
  86.         /* If it is clear, then the other bits are valid and clicking will create an */
  87.         /* appropriate note. */
  88.         unsigned long                        NoteState;
  89.         /* NoteReady is true if NoteState is valid, or False if not */
  90.         MyBoolean                                NoteReady;
  91.  
  92.         WinType*                                ScreenID;
  93.         ScrollRec*                            HScroll;
  94.         ScrollRec*                            VScroll;
  95.         IconButtonRec*                    ArrowButton;
  96.         IconButtonRec*                    CommandButton;
  97.         IconButtonRec*                    SixtyFourthButton;
  98.         IconButtonRec*                    ThirtySecondButton;
  99.         IconButtonRec*                    SixteenthButton;
  100.         IconButtonRec*                    EighthButton;
  101.         IconButtonRec*                    QuarterButton;
  102.         IconButtonRec*                    HalfButton;
  103.         IconButtonRec*                    WholeButton;
  104.         IconButtonRec*                    DoubleButton;
  105.         IconButtonRec*                    QuadButton;
  106.         IconButtonRec*                    SharpButton;
  107.         IconButtonRec*                    FlatButton;
  108.         IconButtonRec*                    NaturalButton;
  109.         IconButtonRec*                    NoteVsRestButton;
  110.         IconButtonRec*                    RestVsNoteButton;
  111.         IconButtonRec*                    NoDotButton;
  112.         IconButtonRec*                    YesDotButton;
  113.         IconButtonRec*                    Div1Button;
  114.         IconButtonRec*                    Div3Button;
  115.         IconButtonRec*                    Div5Button;
  116.         IconButtonRec*                    Div7Button;
  117.         TrackViewRec*                        TrackView;
  118.         GenericWindowRec*                MyGenericWindow; /* how the window event dispatcher knows us */
  119.         MenuItemType*                        MyMenuItem;
  120.  
  121.         /* for doing fun stuff with the play... menu options */
  122.         MyBoolean                                LastMenuOptionKeyDown;
  123.     };
  124.  
  125.  
  126. static void                            TrackWindowVScrollHook(long Parameter, ScrollType How,
  127.                                                     TrackWindowRec* Window);
  128.  
  129. static void                            TrackWindowHScrollHook(long Parameter, ScrollType How,
  130.                                                     TrackWindowRec* Window);
  131.  
  132.  
  133. /* create a new track editing window */
  134. TrackWindowRec*                    NewTrackWindow(struct TrackObjectRec* TrackObject,
  135.                                                     struct MainWindowRec* MainWindow,
  136.                                                     struct TrackListRec* TrackList, short WinX, short WinY,
  137.                                                     short WinWidth, short WinHeight)
  138.     {
  139.         TrackWindowRec*                Window;
  140.         OrdType                                ButtonX;
  141.  
  142.         /* deal with window placement */
  143.         if ((WinWidth < 100) || (WinHeight < 100) || ((eOptionKey & CheckModifiers()) != 0))
  144.             {
  145.                 WinX = 1 + WindowOtherEdgeWidths(eDocumentWindow);
  146.                 WinY = 1 + WindowTitleBarHeight(eDocumentWindow);
  147.                 WinWidth = WINDOWXSIZE;
  148.                 WinHeight = WINDOWYSIZE;
  149.             }
  150.         MakeWindowFitOnScreen(&WinX,&WinY,&WinWidth,&WinHeight);
  151.  
  152.         Window = (TrackWindowRec*)AllocPtrCanFail(sizeof(TrackWindowRec),"TrackWindowRec");
  153.         if (Window == NIL)
  154.             {
  155.              FailurePoint1:
  156.                 return NIL;
  157.             }
  158.         Window->MainWindow = MainWindow;
  159.         Window->TrackObject = TrackObject;
  160.         Window->TrackList = TrackList;
  161.  
  162.         Window->ScreenID = MakeNewWindow(eDocumentWindow,eWindowClosable,eWindowZoomable,
  163.             eWindowResizable,WinX,WinY,WinWidth,WinHeight,(void (*)(void*))&TrackWindowUpdator,
  164.             Window);
  165.         if (Window->ScreenID == 0)
  166.             {
  167.              FailurePoint2:
  168.                 ReleasePtr((char*)Window);
  169.                 goto FailurePoint1;
  170.             }
  171.  
  172.         Window->HScroll = NewScrollBar(Window->ScreenID,eHScrollBar,HSCROLLX,
  173.             HSCROLLY(WinHeight),HSCROLLWIDTH(WinWidth));
  174.         if (Window->HScroll == NIL)
  175.             {
  176.              FailurePoint3:
  177.                 KillWindow(Window->ScreenID);
  178.                 goto FailurePoint2;
  179.             }
  180.  
  181.         Window->VScroll = NewScrollBar(Window->ScreenID,eVScrollBar,VSCROLLX(WinWidth),
  182.             VSCROLLY,VSCROLLHEIGHT(WinHeight));
  183.         if (Window->VScroll == NIL)
  184.             {
  185.              FailurePoint4:
  186.                 DisposeScrollBar(Window->HScroll);
  187.                 goto FailurePoint3;
  188.             }
  189.  
  190.         ButtonX = BUTTONSXSTART;
  191.  
  192.         Window->ArrowButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,BUTTONSY,
  193.             BUTTONWIDTH,BUTTONHEIGHT,ArrowButtonBits,ArrowButtonMouseDownBits,
  194.             ArrowButtonSelectedBits,ArrowButtonSelectedMouseDownBits,eIconRadioMode);
  195.         if (Window->ArrowButton == NIL)
  196.             {
  197.              FailurePoint5:
  198.                 DisposeScrollBar(Window->VScroll);
  199.                 goto FailurePoint4;
  200.             }
  201.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  202.  
  203.         Window->CommandButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  204.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,CommandButtonBits,CommandButtonMouseDownBits,
  205.             CommandButtonSelectedBits,CommandButtonSelectedMouseDownBits,eIconRadioMode);
  206.         if (Window->CommandButton == NIL)
  207.             {
  208.              FailurePoint5point1:
  209.                 DisposeIconButton(Window->ArrowButton);
  210.                 goto FailurePoint5;
  211.             }
  212.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  213.  
  214.         Window->SixtyFourthButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  215.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,SixtyFourthButtonBits,
  216.             SixtyFourthButtonMouseDownBits,SixtyFourthButtonSelectedBits,
  217.             SixtyFourthButtonSelectedMouseDownBits,eIconRadioMode);
  218.         if (Window->SixtyFourthButton == NIL)
  219.             {
  220.              FailurePoint6:
  221.                 DisposeIconButton(Window->CommandButton);
  222.                 goto FailurePoint5point1;
  223.             }
  224.         ButtonX += BUTTONINCREMENT;
  225.  
  226.         Window->ThirtySecondButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  227.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,ThirtySecondButtonBits,
  228.             ThirtySecondButtonMouseDownBits,ThirtySecondButtonSelectedBits,
  229.             ThirtySecondButtonSelectedMouseDownBits,eIconRadioMode);
  230.         if (Window->ThirtySecondButton == NIL)
  231.             {
  232.              FailurePoint7:
  233.                 DisposeIconButton(Window->SixtyFourthButton);
  234.                 goto FailurePoint6;
  235.             }
  236.         ButtonX += BUTTONINCREMENT;
  237.  
  238.         Window->SixteenthButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  239.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,SixteenthButtonBits,
  240.             SixteenthButtonMouseDownBits,SixteenthButtonSelectedBits,
  241.             SixteenthButtonSelectedMouseDownBits,eIconRadioMode);
  242.         if (Window->SixteenthButton == NIL)
  243.             {
  244.              FailurePoint8:
  245.                 DisposeIconButton(Window->ThirtySecondButton);
  246.                 goto FailurePoint7;
  247.             }
  248.         ButtonX += BUTTONINCREMENT;
  249.  
  250.         Window->EighthButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  251.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,EighthButtonBits,
  252.             EighthButtonMouseDownBits,EighthButtonSelectedBits,
  253.             EighthButtonSelectedMouseDownBits,eIconRadioMode);
  254.         if (Window->EighthButton == NIL)
  255.             {
  256.              FailurePoint9:
  257.                 DisposeIconButton(Window->SixteenthButton);
  258.                 goto FailurePoint8;
  259.             }
  260.         ButtonX += BUTTONINCREMENT;
  261.  
  262.         Window->QuarterButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  263.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,QuarterButtonBits,
  264.             QuarterButtonMouseDownBits,QuarterButtonSelectedBits,
  265.             QuarterButtonSelectedMouseDownBits,eIconRadioMode);
  266.         if (Window->QuarterButton == NIL)
  267.             {
  268.              FailurePoint10:
  269.                 DisposeIconButton(Window->EighthButton);
  270.                 goto FailurePoint9;
  271.             }
  272.         ButtonX += BUTTONINCREMENT;
  273.  
  274.         Window->HalfButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  275.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,HalfButtonBits,HalfButtonMouseDownBits,
  276.             HalfButtonSelectedBits,HalfButtonSelectedMouseDownBits,eIconRadioMode);
  277.         if (Window->HalfButton == NIL)
  278.             {
  279.              FailurePoint11:
  280.                 DisposeIconButton(Window->QuarterButton);
  281.                 goto FailurePoint10;
  282.             }
  283.         ButtonX += BUTTONINCREMENT;
  284.  
  285.         Window->WholeButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  286.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,WholeButtonBits,WholeButtonMouseDownBits,
  287.             WholeButtonSelectedBits,WholeButtonSelectedMouseDownBits,eIconRadioMode);
  288.         if (Window->WholeButton == NIL)
  289.             {
  290.              FailurePoint12:
  291.                 DisposeIconButton(Window->HalfButton);
  292.                 goto FailurePoint11;
  293.             }
  294.         ButtonX += BUTTONINCREMENT;
  295.  
  296.         Window->DoubleButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  297.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,DoubleButtonBits,DoubleButtonMouseDownBits,
  298.             DoubleButtonSelectedBits,DoubleButtonSelectedMouseDownBits,eIconRadioMode);
  299.         if (Window->DoubleButton == NIL)
  300.             {
  301.              FailurePoint13:
  302.                 DisposeIconButton(Window->WholeButton);
  303.                 goto FailurePoint12;
  304.             }
  305.         ButtonX += BUTTONINCREMENT;
  306.  
  307.         Window->QuadButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  308.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,QuadButtonBits,QuadButtonMouseDownBits,
  309.             QuadButtonSelectedBits,QuadButtonSelectedMouseDownBits,eIconRadioMode);
  310.         if (Window->QuadButton == NIL)
  311.             {
  312.              FailurePoint14:
  313.                 DisposeIconButton(Window->DoubleButton);
  314.                 goto FailurePoint13;
  315.             }
  316.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  317.  
  318.         Window->SharpButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  319.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,SharpButtonBits,SharpButtonMouseDownBits,
  320.             SharpButtonSelectedBits,SharpButtonSelectedMouseDownBits,eIconRadioMode);
  321.         if (Window->SharpButton == NIL)
  322.             {
  323.              FailurePoint15:
  324.                 DisposeIconButton(Window->QuadButton);
  325.                 goto FailurePoint14;
  326.             }
  327.         ButtonX += BUTTONINCREMENT;
  328.  
  329.         Window->FlatButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  330.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,FlatButtonBits,FlatButtonMouseDownBits,
  331.             FlatButtonSelectedBits,FlatButtonSelectedMouseDownBits,eIconRadioMode);
  332.         if (Window->FlatButton == NIL)
  333.             {
  334.              FailurePoint16:
  335.                 DisposeIconButton(Window->SharpButton);
  336.                 goto FailurePoint15;
  337.             }
  338.         ButtonX += BUTTONINCREMENT;
  339.  
  340.         Window->NaturalButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  341.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,NaturalButtonBits,NaturalButtonMouseDownBits,
  342.             NaturalButtonSelectedBits,NaturalButtonSelectedMouseDownBits,eIconRadioMode);
  343.         if (Window->NaturalButton == NIL)
  344.             {
  345.              FailurePoint17:
  346.                 DisposeIconButton(Window->FlatButton);
  347.                 goto FailurePoint16;
  348.             }
  349.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  350.  
  351.         Window->NoteVsRestButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  352.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,NoteVsRestButtonBits,
  353.             NoteVsRestButtonMouseDownBits,NoteVsRestButtonSelectedBits,
  354.             NoteVsRestButtonSelectedMouseDownBits,eIconRadioMode);
  355.         if (Window->NoteVsRestButton == NIL)
  356.             {
  357.              FailurePoint18:
  358.                 DisposeIconButton(Window->NaturalButton);
  359.                 goto FailurePoint17;
  360.             }
  361.         ButtonX += BUTTONINCREMENT;
  362.  
  363.         Window->RestVsNoteButton = NewIconButtonPreparedBitmaps(Window->ScreenID,
  364.             ButtonX,BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,RestVsNoteButtonBits,
  365.             RestVsNoteButtonMouseDownBits,RestVsNoteButtonSelectedBits,
  366.             RestVsNoteButtonSelectedMouseDownBits,eIconRadioMode);
  367.         if (Window->RestVsNoteButton == NIL)
  368.             {
  369.              FailurePoint19:
  370.                 DisposeIconButton(Window->NoteVsRestButton);
  371.                 goto FailurePoint18;
  372.             }
  373.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  374.  
  375.         Window->NoDotButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  376.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,NoDotButtonBits,NoDotButtonMouseDownBits,
  377.             NoDotButtonSelectedBits,NoDotButtonSelectedMouseDownBits,eIconRadioMode);
  378.         if (Window->NoDotButton == NIL)
  379.             {
  380.              FailurePoint20:
  381.                 DisposeIconButton(Window->RestVsNoteButton);
  382.                 goto FailurePoint19;
  383.             }
  384.         ButtonX += BUTTONINCREMENT;
  385.  
  386.         Window->YesDotButton = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  387.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,YesDotButtonBits,YesDotButtonMouseDownBits,
  388.             YesDotButtonSelectedBits,YesDotButtonSelectedMouseDownBits,eIconRadioMode);
  389.         if (Window->YesDotButton == NIL)
  390.             {
  391.              FailurePoint21:
  392.                 DisposeIconButton(Window->NoDotButton);
  393.                 goto FailurePoint20;
  394.             }
  395.         ButtonX += BUTTONINCREMENT + BUTTONEXOINCREMENT;
  396.  
  397.         Window->Div1Button = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  398.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,Div1ButtonBits,Div1ButtonMouseDownBits,
  399.             Div1ButtonSelectedBits,Div1ButtonSelectedMouseDownBits,eIconRadioMode);
  400.         if (Window->Div1Button == NIL)
  401.             {
  402.              FailurePoint22:
  403.                 DisposeIconButton(Window->YesDotButton);
  404.                 goto FailurePoint21;
  405.             }
  406.         ButtonX += BUTTONINCREMENT;
  407.  
  408.         Window->Div3Button = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  409.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,Div3ButtonBits,Div3ButtonMouseDownBits,
  410.             Div3ButtonSelectedBits,Div3ButtonSelectedMouseDownBits,eIconRadioMode);
  411.         if (Window->Div3Button == NIL)
  412.             {
  413.              FailurePoint23:
  414.                 DisposeIconButton(Window->Div1Button);
  415.                 goto FailurePoint22;
  416.             }
  417.         ButtonX += BUTTONINCREMENT;
  418.  
  419.         Window->Div5Button = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  420.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,Div5ButtonBits,Div5ButtonMouseDownBits,
  421.             Div5ButtonSelectedBits,Div5ButtonSelectedMouseDownBits,eIconRadioMode);
  422.         if (Window->Div5Button == NIL)
  423.             {
  424.              FailurePoint24:
  425.                 DisposeIconButton(Window->Div3Button);
  426.                 goto FailurePoint23;
  427.             }
  428.         ButtonX += BUTTONINCREMENT;
  429.  
  430.         Window->Div7Button = NewIconButtonPreparedBitmaps(Window->ScreenID,ButtonX,
  431.             BUTTONSY,BUTTONWIDTH,BUTTONHEIGHT,Div7ButtonBits, Div7ButtonMouseDownBits,
  432.             Div7ButtonSelectedBits,Div7ButtonSelectedMouseDownBits,eIconRadioMode);
  433.         if (Window->Div7Button == NIL)
  434.             {
  435.              FailurePoint25:
  436.                 DisposeIconButton(Window->Div5Button);
  437.                 goto FailurePoint24;
  438.             }
  439.  
  440.         Window->TrackView = NewTrackView(TrackObject,Window->ScreenID,TRACKVIEWX,
  441.             TRACKVIEWY,TRACKVIEWWIDTH(WinWidth),TRACKVIEWHEIGHT(WinHeight));
  442.         if (Window->TrackView == NIL)
  443.             {
  444.              FailurePoint26:
  445.                 DisposeIconButton(Window->Div7Button);
  446.                 goto FailurePoint25;
  447.             }
  448.  
  449.         Window->MyGenericWindow = CheckInNewWindow(Window->ScreenID,Window,
  450.             (void (*)(void*,MyBoolean,OrdType,OrdType,ModifierFlags))&TrackWindowDoIdle,
  451.             (void (*)(void*))&TrackWindowBecomeActive,
  452.             (void (*)(void*))&TrackWindowBecomeInactive,
  453.             (void (*)(void*))&TrackWindowJustResized,
  454.             (void (*)(OrdType,OrdType,ModifierFlags,void*))&TrackWindowDoMouseDown,
  455.             (void (*)(unsigned char,ModifierFlags,void*))&TrackWindowDoKeyDown,
  456.             (void (*)(void*))&TrackWindowClose,
  457.             (void (*)(void*))&TrackWindowMenuSetup,
  458.             (void (*)(void*,MenuItemType*))&TrackWindowDoMenuCommand);
  459.         if (Window->MyGenericWindow == NIL)
  460.             {
  461.              FailurePoint27:
  462.                 DisposeTrackView(Window->TrackView);
  463.                 goto FailurePoint26;
  464.             }
  465.  
  466.         Window->MyMenuItem = MakeNewMenuItem(mmWindowMenu,"x",0);
  467.         if (Window->MyMenuItem == NIL)
  468.             {
  469.              FailurePoint28:
  470.                 CheckOutDyingWindow(Window->MyGenericWindow);
  471.                 goto FailurePoint27;
  472.             }
  473.         if (!RegisterWindowMenuItem(Window->MyMenuItem,(void (*)(void*))&ActivateThisWindow,
  474.             Window->ScreenID))
  475.             {
  476.              FailurePoint29:
  477.                 KillMenuItem(Window->MyMenuItem);
  478.                 goto FailurePoint28;
  479.             }
  480.  
  481.         Window->NoteState = e4thNote | eDiv1Modifier;
  482.         Window->NoteReady = False;
  483.         TrackWindowUpdateScrollBars(Window);
  484.         TrackWindowResetButtons(Window);
  485.         TrackWindowResetTitlebar(Window);
  486.  
  487.         return Window;
  488.     }
  489.  
  490.  
  491. /* dispose of the track editing window. */
  492. void                                        DisposeTrackWindow(TrackWindowRec* Window)
  493.     {
  494.         CheckPtrExistence(Window);
  495.         HideMenu(TrackListGetTrackMenu(Window->TrackList));
  496.         TrackObjectClosingWindowNotify(Window->TrackObject,
  497.             GetWindowXStart(Window->ScreenID),GetWindowYStart(Window->ScreenID),
  498.             GetWindowWidth(Window->ScreenID),GetWindowHeight(Window->ScreenID));
  499.         DeregisterWindowMenuItem(Window->MyMenuItem);
  500.         KillMenuItem(Window->MyMenuItem);
  501.         CheckOutDyingWindow(Window->MyGenericWindow);
  502.         DisposeTrackView(Window->TrackView);
  503.         DisposeScrollBar(Window->HScroll);
  504.         DisposeScrollBar(Window->VScroll);
  505.         DisposeIconButton(Window->ArrowButton);
  506.         DisposeIconButton(Window->CommandButton);
  507.         DisposeIconButton(Window->SixtyFourthButton);
  508.         DisposeIconButton(Window->ThirtySecondButton);
  509.         DisposeIconButton(Window->SixteenthButton);
  510.         DisposeIconButton(Window->EighthButton);
  511.         DisposeIconButton(Window->QuarterButton);
  512.         DisposeIconButton(Window->HalfButton);
  513.         DisposeIconButton(Window->WholeButton);
  514.         DisposeIconButton(Window->DoubleButton);
  515.         DisposeIconButton(Window->QuadButton);
  516.         DisposeIconButton(Window->SharpButton);
  517.         DisposeIconButton(Window->FlatButton);
  518.         DisposeIconButton(Window->NaturalButton);
  519.         DisposeIconButton(Window->NoteVsRestButton);
  520.         DisposeIconButton(Window->RestVsNoteButton);
  521.         DisposeIconButton(Window->NoDotButton);
  522.         DisposeIconButton(Window->YesDotButton);
  523.         DisposeIconButton(Window->Div1Button);
  524.         DisposeIconButton(Window->Div3Button);
  525.         DisposeIconButton(Window->Div5Button);
  526.         DisposeIconButton(Window->Div7Button);
  527.         KillWindow(Window->ScreenID);
  528.         ReleasePtr((char*)Window);
  529.     }
  530.  
  531.  
  532. /* bring the track window to the top and give it the focus */
  533. void                                        TrackWindowBringToTop(TrackWindowRec* Window)
  534.     {
  535.         CheckPtrExistence(Window);
  536.         ActivateThisWindow(Window->ScreenID);
  537.     }
  538.  
  539.  
  540. void                                        TrackWindowDoIdle(TrackWindowRec* Window,
  541.                                                     MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
  542.                                                     ModifierFlags Modifiers)
  543.     {
  544.         CheckPtrExistence(Window);
  545.         /* check mouse EVERY time, not just on mouse update cycles */
  546.         if (TrackViewHitTest(Window->TrackView,XLoc,YLoc))
  547.             {
  548.                 /* note plotting mode cursor */
  549.                 TrackViewUpdateMouseCursor(Window->TrackView,XLoc,YLoc,Window->NoteReady);
  550.             }
  551.          else
  552.             {
  553.                 TrackViewUndrawCursorBar(Window->TrackView);
  554.                 SetArrowCursor();
  555.             }
  556.     }
  557.  
  558.  
  559. void                                        TrackWindowBecomeActive(TrackWindowRec* Window)
  560.     {
  561.         OrdType                                XSize;
  562.         OrdType                                YSize;
  563.  
  564.         CheckPtrExistence(Window);
  565.         XSize = GetWindowWidth(Window->ScreenID);
  566.         YSize = GetWindowHeight(Window->ScreenID);
  567.         EnableScrollBar(Window->HScroll);
  568.         EnableScrollBar(Window->VScroll);
  569.         /* force redraw of track view object to incorporate any changes to tracks */
  570.         /* displayed in this window (since we don't redraw it in the background in */
  571.         /* order to save time) */
  572.         MarkForDeferredUpdate(Window->ScreenID);
  573.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  574.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(True/*enablegrowicon*/));
  575.         /* decrease lag time so that we update cursor more often */
  576.         SetEventSleepTime(0.1);
  577.         ShowMenu(TrackListGetTrackMenu(Window->TrackList));
  578.     }
  579.  
  580.  
  581. void                                        TrackWindowBecomeInactive(TrackWindowRec* Window)
  582.     {
  583.         OrdType                                XSize;
  584.         OrdType                                YSize;
  585.  
  586.         CheckPtrExistence(Window);
  587.         XSize = GetWindowWidth(Window->ScreenID);
  588.         YSize = GetWindowHeight(Window->ScreenID);
  589.         DisableScrollBar(Window->HScroll);
  590.         DisableScrollBar(Window->VScroll);
  591.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  592.         DrawBitmap(Window->ScreenID,XSize-15,YSize-15,GetGrowIcon(False/*disablegrowicon*/));
  593.         /* reset event delay time to default */
  594.         SetEventSleepTime(0.25);
  595.         HideMenu(TrackListGetTrackMenu(Window->TrackList));
  596.     }
  597.  
  598.  
  599. void                                        TrackWindowJustResized(TrackWindowRec* Window)
  600.     {
  601.         OrdType                                XSize;
  602.         OrdType                                YSize;
  603.  
  604.         CheckPtrExistence(Window);
  605.         XSize = GetWindowWidth(Window->ScreenID);
  606.         YSize = GetWindowHeight(Window->ScreenID);
  607.         SetClipRect(Window->ScreenID,0,0,XSize,YSize);
  608.         DrawBoxErase(Window->ScreenID,0,0,XSize,YSize);
  609.         SetTrackViewPosition(Window->TrackView,TRACKVIEWX,TRACKVIEWY,
  610.             TRACKVIEWWIDTH(XSize),TRACKVIEWHEIGHT(YSize));
  611.         TrackWindowUpdateScrollBars(Window);
  612.         SetScrollLocation(Window->HScroll,HSCROLLX,HSCROLLY(YSize),HSCROLLWIDTH(XSize));
  613.         SetScrollLocation(Window->VScroll,VSCROLLX(XSize),VSCROLLY,VSCROLLHEIGHT(YSize));
  614.     }
  615.  
  616.  
  617. void                                        TrackWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
  618.                                                     ModifierFlags Modifiers, TrackWindowRec* Window)
  619.     {
  620.         if ((XLoc >= GetWindowWidth(Window->ScreenID) - 15)
  621.             && (XLoc < GetWindowWidth(Window->ScreenID))
  622.             && (YLoc >= GetWindowHeight(Window->ScreenID) - 15)
  623.             && (YLoc < GetWindowHeight(Window->ScreenID)))
  624.             {
  625.                 UserGrowWindow(Window->ScreenID,XLoc,YLoc);
  626.                 TrackWindowJustResized(Window);
  627.             }
  628.         else if (ScrollHitTest(Window->VScroll,XLoc,YLoc))
  629.             {
  630.                 ScrollHitProc(Window->VScroll,Modifiers,XLoc,YLoc,Window,
  631.                     (void (*)(long, ScrollType, void*))&TrackWindowVScrollHook);
  632.             }
  633.         else if (ScrollHitTest(Window->HScroll,XLoc,YLoc))
  634.             {
  635.                 ScrollHitProc(Window->HScroll,Modifiers,XLoc,YLoc,Window,
  636.                     (void (*)(long, ScrollType, void*))&TrackWindowHScrollHook);
  637.             }
  638.         else if (IconButtonHitTest(Window->ArrowButton,XLoc,YLoc))
  639.             {
  640.                 if (IconButtonMouseDown(Window->ArrowButton,XLoc,YLoc,NIL,NIL))
  641.                     {
  642.                         Window->NoteReady = False;
  643.                         TrackWindowResetButtons(Window);
  644.                         TrackViewUndrawCursorBar(Window->TrackView);
  645.                     }
  646.             }
  647.         else if (IconButtonHitTest(Window->CommandButton,XLoc,YLoc))
  648.             {
  649.                 if (IconButtonMouseDown(Window->CommandButton,XLoc,YLoc,NIL,NIL))
  650.                     {
  651.                         Window->NoteReady = True;
  652.                         Window->NoteState |= eCommandFlag;
  653.                         TrackWindowResetButtons(Window);
  654.                     }
  655.             }
  656.         else if (IconButtonHitTest(Window->SixtyFourthButton,XLoc,YLoc))
  657.             {
  658.                 if (IconButtonMouseDown(Window->SixtyFourthButton,XLoc,YLoc,NIL,NIL))
  659.                     {
  660.                         Window->NoteReady = True;
  661.                         Window->NoteState &= ~eCommandFlag;
  662.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e64thNote;
  663.                         TrackWindowResetButtons(Window);
  664.                     }
  665.             }
  666.         else if (IconButtonHitTest(Window->ThirtySecondButton,XLoc,YLoc))
  667.             {
  668.                 if (IconButtonMouseDown(Window->ThirtySecondButton,XLoc,YLoc,NIL,NIL))
  669.                     {
  670.                         Window->NoteReady = True;
  671.                         Window->NoteState &= ~eCommandFlag;
  672.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e32ndNote;
  673.                         TrackWindowResetButtons(Window);
  674.                     }
  675.             }
  676.         else if (IconButtonHitTest(Window->SixteenthButton,XLoc,YLoc))
  677.             {
  678.                 if (IconButtonMouseDown(Window->SixteenthButton,XLoc,YLoc,NIL,NIL))
  679.                     {
  680.                         Window->NoteReady = True;
  681.                         Window->NoteState &= ~eCommandFlag;
  682.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e16thNote;
  683.                         TrackWindowResetButtons(Window);
  684.                     }
  685.             }
  686.         else if (IconButtonHitTest(Window->EighthButton,XLoc,YLoc))
  687.             {
  688.                 if (IconButtonMouseDown(Window->EighthButton,XLoc,YLoc,NIL,NIL))
  689.                     {
  690.                         Window->NoteReady = True;
  691.                         Window->NoteState &= ~eCommandFlag;
  692.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e8thNote;
  693.                         TrackWindowResetButtons(Window);
  694.                     }
  695.             }
  696.         else if (IconButtonHitTest(Window->QuarterButton,XLoc,YLoc))
  697.             {
  698.                 if (IconButtonMouseDown(Window->QuarterButton,XLoc,YLoc,NIL,NIL))
  699.                     {
  700.                         Window->NoteReady = True;
  701.                         Window->NoteState &= ~eCommandFlag;
  702.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e4thNote;
  703.                         TrackWindowResetButtons(Window);
  704.                     }
  705.             }
  706.         else if (IconButtonHitTest(Window->HalfButton,XLoc,YLoc))
  707.             {
  708.                 if (IconButtonMouseDown(Window->HalfButton,XLoc,YLoc,NIL,NIL))
  709.                     {
  710.                         Window->NoteReady = True;
  711.                         Window->NoteState &= ~eCommandFlag;
  712.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | e2ndNote;
  713.                         TrackWindowResetButtons(Window);
  714.                     }
  715.             }
  716.         else if (IconButtonHitTest(Window->WholeButton,XLoc,YLoc))
  717.             {
  718.                 if (IconButtonMouseDown(Window->WholeButton,XLoc,YLoc,NIL,NIL))
  719.                     {
  720.                         Window->NoteReady = True;
  721.                         Window->NoteState &= ~eCommandFlag;
  722.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | eWholeNote;
  723.                         TrackWindowResetButtons(Window);
  724.                     }
  725.             }
  726.         else if (IconButtonHitTest(Window->DoubleButton,XLoc,YLoc))
  727.             {
  728.                 if (IconButtonMouseDown(Window->DoubleButton,XLoc,YLoc,NIL,NIL))
  729.                     {
  730.                         Window->NoteReady = True;
  731.                         Window->NoteState &= ~eCommandFlag;
  732.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | eDoubleNote;
  733.                         TrackWindowResetButtons(Window);
  734.                     }
  735.             }
  736.         else if (IconButtonHitTest(Window->QuadButton,XLoc,YLoc))
  737.             {
  738.                 if (IconButtonMouseDown(Window->QuadButton,XLoc,YLoc,NIL,NIL))
  739.                     {
  740.                         Window->NoteReady = True;
  741.                         Window->NoteState &= ~eCommandFlag;
  742.                         Window->NoteState = (Window->NoteState & ~eDurationMask) | eQuadNote;
  743.                         TrackWindowResetButtons(Window);
  744.                     }
  745.             }
  746.         else if (IconButtonHitTest(Window->SharpButton,XLoc,YLoc))
  747.             {
  748.                 if (IconButtonMouseDown(Window->SharpButton,XLoc,YLoc,NIL,NIL))
  749.                     {
  750.                         Window->NoteReady = True;
  751.                         Window->NoteState &= ~eCommandFlag;
  752.                         Window->NoteState = (Window->NoteState & ~eFlatModifier) | eSharpModifier;
  753.                         TrackWindowResetButtons(Window);
  754.                     }
  755.             }
  756.         else if (IconButtonHitTest(Window->FlatButton,XLoc,YLoc))
  757.             {
  758.                 if (IconButtonMouseDown(Window->FlatButton,XLoc,YLoc,NIL,NIL))
  759.                     {
  760.                         Window->NoteReady = True;
  761.                         Window->NoteState &= ~eCommandFlag;
  762.                         Window->NoteState = (Window->NoteState & ~eSharpModifier) | eFlatModifier;
  763.                         TrackWindowResetButtons(Window);
  764.                     }
  765.             }
  766.         else if (IconButtonHitTest(Window->NaturalButton,XLoc,YLoc))
  767.             {
  768.                 if (IconButtonMouseDown(Window->NaturalButton,XLoc,YLoc,NIL,NIL))
  769.                     {
  770.                         Window->NoteReady = True;
  771.                         Window->NoteState &= ~eCommandFlag;
  772.                         Window->NoteState = Window->NoteState & ~(eSharpModifier | eFlatModifier);
  773.                         TrackWindowResetButtons(Window);
  774.                     }
  775.             }
  776.         else if (IconButtonHitTest(Window->NoteVsRestButton,XLoc,YLoc))
  777.             {
  778.                 if (IconButtonMouseDown(Window->NoteVsRestButton,XLoc,YLoc,NIL,NIL))
  779.                     {
  780.                         Window->NoteReady = True;
  781.                         Window->NoteState &= ~eCommandFlag;
  782.                         Window->NoteState = Window->NoteState & ~eRestModifier;
  783.                         TrackWindowResetButtons(Window);
  784.                     }
  785.             }
  786.         else if (IconButtonHitTest(Window->RestVsNoteButton,XLoc,YLoc))
  787.             {
  788.                 if (IconButtonMouseDown(Window->RestVsNoteButton,XLoc,YLoc,NIL,NIL))
  789.                     {
  790.                         Window->NoteReady = True;
  791.                         Window->NoteState &= ~eCommandFlag;
  792.                         Window->NoteState = Window->NoteState | eRestModifier;
  793.                         TrackWindowResetButtons(Window);
  794.                     }
  795.             }
  796.         else if (IconButtonHitTest(Window->NoDotButton,XLoc,YLoc))
  797.             {
  798.                 if (IconButtonMouseDown(Window->NoDotButton,XLoc,YLoc,NIL,NIL))
  799.                     {
  800.                         Window->NoteReady = True;
  801.                         Window->NoteState &= ~eCommandFlag;
  802.                         Window->NoteState = Window->NoteState & ~eDotModifier;
  803.                         TrackWindowResetButtons(Window);
  804.                     }
  805.             }
  806.         else if (IconButtonHitTest(Window->YesDotButton,XLoc,YLoc))
  807.             {
  808.                 if (IconButtonMouseDown(Window->YesDotButton,XLoc,YLoc,NIL,NIL))
  809.                     {
  810.                         Window->NoteReady = True;
  811.                         Window->NoteState &= ~eCommandFlag;
  812.                         Window->NoteState = Window->NoteState | eDotModifier;
  813.                         TrackWindowResetButtons(Window);
  814.                     }
  815.             }
  816.         else if (IconButtonHitTest(Window->Div1Button,XLoc,YLoc))
  817.             {
  818.                 if (IconButtonMouseDown(Window->Div1Button,XLoc,YLoc,NIL,NIL))
  819.                     {
  820.                         Window->NoteReady = True;
  821.                         Window->NoteState &= ~eCommandFlag;
  822.                         Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv1Modifier;
  823.                         TrackWindowResetButtons(Window);
  824.                     }
  825.             }
  826.         else if (IconButtonHitTest(Window->Div3Button,XLoc,YLoc))
  827.             {
  828.                 if (IconButtonMouseDown(Window->Div3Button,XLoc,YLoc,NIL,NIL))
  829.                     {
  830.                         Window->NoteReady = True;
  831.                         Window->NoteState &= ~eCommandFlag;
  832.                         Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv3Modifier;
  833.                         TrackWindowResetButtons(Window);
  834.                     }
  835.             }
  836.         else if (IconButtonHitTest(Window->Div5Button,XLoc,YLoc))
  837.             {
  838.                 if (IconButtonMouseDown(Window->Div5Button,XLoc,YLoc,NIL,NIL))
  839.                     {
  840.                         Window->NoteReady = True;
  841.                         Window->NoteState &= ~eCommandFlag;
  842.                         Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv5Modifier;
  843.                         TrackWindowResetButtons(Window);
  844.                     }
  845.             }
  846.         else if (IconButtonHitTest(Window->Div7Button,XLoc,YLoc))
  847.             {
  848.                 if (IconButtonMouseDown(Window->Div7Button,XLoc,YLoc,NIL,NIL))
  849.                     {
  850.                         Window->NoteReady = True;
  851.                         Window->NoteState &= ~eCommandFlag;
  852.                         Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv7Modifier;
  853.                         TrackWindowResetButtons(Window);
  854.                     }
  855.             }
  856.         else if (TrackViewHitTest(Window->TrackView,XLoc,YLoc))
  857.             {
  858.                 if ((Modifiers & eCommandKey) != 0)
  859.                     {
  860.                         /* single note selection */
  861.                         TrackViewTrySingleNoteSelection(Window->TrackView,XLoc,YLoc);
  862.                     }
  863.                 else if ((Modifiers & eControlKey) != 0)
  864.                     {
  865.                         /* set ties */
  866.                         if (TrackViewIsASingleNoteSelected(Window->TrackView))
  867.                             {
  868.                                 TrackViewSetTieOnNote(Window->TrackView,XLoc,YLoc);
  869.                             }
  870.                     }
  871.                 else
  872.                     {
  873.                         if (Window->NoteReady && ((Modifiers & eShiftKey) == 0))
  874.                             {
  875.                                 if ((Window->NoteState & eCommandFlag) == 0)
  876.                                     {
  877.                                         /* adding a note to the track */
  878.                                         TrackViewAddNote(Window->TrackView,XLoc,YLoc,Window->NoteState);
  879.                                     }
  880.                                  else
  881.                                     {
  882.                                         NoteCommands                TheCommandTheyWant;
  883.  
  884.                                         /* adding a command to the track */
  885.                                         if (ChooseCommandFromList(&TheCommandTheyWant))
  886.                                             {
  887.                                                 TrackViewAddCommand(Window->TrackView,XLoc,YLoc,
  888.                                                     TheCommandTheyWant);
  889.                                             }
  890.                                     }
  891.                             }
  892.                          else
  893.                             {
  894.                                 /* block selection */
  895.                                 TrackViewDoMouseDown(Window->TrackView,XLoc,YLoc,
  896.                                     ((Modifiers & eShiftKey) != 0),
  897.                                     (void (*)(void *))&TrackWindowUpdateScrollBars,Window);
  898.                             }
  899.                         TrackWindowUpdateHScrollBar(Window);
  900.                     }
  901.             }
  902.     }
  903.  
  904.  
  905. void                                        TrackWindowDoKeyDown(unsigned char KeyCode,
  906.                                                     ModifierFlags Modifiers, TrackWindowRec* Window)
  907.     {
  908.         CheckPtrExistence(Window);
  909.         if ((Modifiers & eCommandKey) != 0)
  910.             {
  911.                 /* don't pay attention to errant menu shortcuts */
  912.                 return;
  913.             }
  914.         switch (KeyCode)
  915.             {
  916.                 case eLeftArrow:
  917.                     TrackWindowHScrollHook(0,eScrollLineMinus,Window);
  918.                     break;
  919.                 case eRightArrow:
  920.                     TrackWindowHScrollHook(0,eScrollLinePlus,Window);
  921.                     break;
  922.                 case eUpArrow:
  923.                     TrackWindowVScrollHook(0,eScrollLineMinus,Window);
  924.                     break;
  925.                 case eDownArrow:
  926.                     TrackWindowVScrollHook(0,eScrollLinePlus,Window);
  927.                     break;
  928.                 case '/':
  929.                     Window->NoteReady = True;
  930.                     Window->NoteState = e4thNote | eDiv1Modifier;
  931.                     TrackWindowResetButtons(Window);
  932.                     TrackViewUndrawCursorBar(Window->TrackView);
  933.                     break;
  934.                 case 'a':
  935.                 case eCancelKey:
  936.                     Window->NoteReady = False;
  937.                     TrackWindowResetButtons(Window);
  938.                     TrackViewUndrawCursorBar(Window->TrackView);
  939.                     break;
  940.                 case 'z':
  941.                     Window->NoteReady = True;
  942.                     Window->NoteState &= ~eCommandFlag;
  943.                     TrackWindowResetButtons(Window);
  944.                     TrackViewUndrawCursorBar(Window->TrackView);
  945.                     break;
  946.                 case 'x':
  947.                     Window->NoteReady = True;
  948.                     Window->NoteState &= ~eCommandFlag;
  949.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e64thNote;
  950.                     TrackWindowResetButtons(Window);
  951.                     break;
  952.                 case 't':
  953.                     Window->NoteReady = True;
  954.                     Window->NoteState &= ~eCommandFlag;
  955.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e32ndNote;
  956.                     TrackWindowResetButtons(Window);
  957.                     break;
  958.                 case 's':
  959.                     Window->NoteReady = True;
  960.                     Window->NoteState &= ~eCommandFlag;
  961.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e16thNote;
  962.                     TrackWindowResetButtons(Window);
  963.                     break;
  964.                 case 'e':
  965.                     Window->NoteReady = True;
  966.                     Window->NoteState &= ~eCommandFlag;
  967.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e8thNote;
  968.                     TrackWindowResetButtons(Window);
  969.                     break;
  970.                 case 'q':
  971.                     Window->NoteReady = True;
  972.                     Window->NoteState &= ~eCommandFlag;
  973.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e4thNote;
  974.                     TrackWindowResetButtons(Window);
  975.                     break;
  976.                 case 'h':
  977.                     Window->NoteReady = True;
  978.                     Window->NoteState &= ~eCommandFlag;
  979.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | e2ndNote;
  980.                     TrackWindowResetButtons(Window);
  981.                     break;
  982.                 case 'w':
  983.                     Window->NoteReady = True;
  984.                     Window->NoteState &= ~eCommandFlag;
  985.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | eWholeNote;
  986.                     TrackWindowResetButtons(Window);
  987.                     break;
  988.                 case 'd':
  989.                     Window->NoteReady = True;
  990.                     Window->NoteState &= ~eCommandFlag;
  991.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | eDoubleNote;
  992.                     TrackWindowResetButtons(Window);
  993.                     break;
  994.                 case 'f':
  995.                     Window->NoteReady = True;
  996.                     Window->NoteState &= ~eCommandFlag;
  997.                     Window->NoteState = (Window->NoteState & ~eDurationMask) | eQuadNote;
  998.                     TrackWindowResetButtons(Window);
  999.                     break;
  1000.                 case '=':
  1001.                 case '+':
  1002.                     Window->NoteReady = True;
  1003.                     Window->NoteState &= ~eCommandFlag;
  1004.                     Window->NoteState = (Window->NoteState & ~eFlatModifier) | eSharpModifier;
  1005.                     TrackWindowResetButtons(Window);
  1006.                     break;
  1007.                 case '-':
  1008.                 case '_':
  1009.                     Window->NoteReady = True;
  1010.                     Window->NoteState &= ~eCommandFlag;
  1011.                     Window->NoteState = (Window->NoteState & ~eSharpModifier) | eFlatModifier;
  1012.                     TrackWindowResetButtons(Window);
  1013.                     break;
  1014.                 case '0':
  1015.                     Window->NoteReady = True;
  1016.                     Window->NoteState &= ~eCommandFlag;
  1017.                     Window->NoteState = Window->NoteState & ~(eSharpModifier | eFlatModifier);
  1018.                     TrackWindowResetButtons(Window);
  1019.                     break;
  1020.                 case 'n':
  1021.                     Window->NoteReady = True;
  1022.                     Window->NoteState &= ~eCommandFlag;
  1023.                     Window->NoteState = Window->NoteState & ~eRestModifier;
  1024.                     TrackWindowResetButtons(Window);
  1025.                     break;
  1026.                 case 'r':
  1027.                     Window->NoteReady = True;
  1028.                     Window->NoteState &= ~eCommandFlag;
  1029.                     Window->NoteState = Window->NoteState | eRestModifier;
  1030.                     TrackWindowResetButtons(Window);
  1031.                     break;
  1032.                 case ',':
  1033.                     Window->NoteReady = True;
  1034.                     Window->NoteState &= ~eCommandFlag;
  1035.                     Window->NoteState = Window->NoteState & ~eDotModifier;
  1036.                     TrackWindowResetButtons(Window);
  1037.                     break;
  1038.                 case '.':
  1039.                     Window->NoteReady = True;
  1040.                     Window->NoteState &= ~eCommandFlag;
  1041.                     Window->NoteState = Window->NoteState | eDotModifier;
  1042.                     TrackWindowResetButtons(Window);
  1043.                     break;
  1044.                 case '1':
  1045.                     Window->NoteReady = True;
  1046.                     Window->NoteState &= ~eCommandFlag;
  1047.                     Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv1Modifier;
  1048.                     TrackWindowResetButtons(Window);
  1049.                     break;
  1050.                 case '3':
  1051.                     Window->NoteReady = True;
  1052.                     Window->NoteState &= ~eCommandFlag;
  1053.                     Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv3Modifier;
  1054.                     TrackWindowResetButtons(Window);
  1055.                     break;
  1056.                 case '5':
  1057.                     Window->NoteReady = True;
  1058.                     Window->NoteState &= ~eCommandFlag;
  1059.                     Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv5Modifier;
  1060.                     TrackWindowResetButtons(Window);
  1061.                     break;
  1062.                 case '7':
  1063.                     Window->NoteReady = True;
  1064.                     Window->NoteState &= ~eCommandFlag;
  1065.                     Window->NoteState = (Window->NoteState & ~eDivisionMask) | eDiv7Modifier;
  1066.                     TrackWindowResetButtons(Window);
  1067.                     break;
  1068.                 case 'c':
  1069.                     Window->NoteReady = True;
  1070.                     Window->NoteState |= eCommandFlag;
  1071.                     TrackWindowResetButtons(Window);
  1072.                     break;
  1073.                 case 8:
  1074.                     /* the delete key deletes selected stuff */
  1075.                     if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1076.                         || TrackViewIsASingleCommandSelected(Window->TrackView))
  1077.                         {
  1078.                             TrackViewDeleteSingleNoteOrCommand(Window->TrackView);
  1079.                         }
  1080.                     else if (TrackViewIsARangeSelected(Window->TrackView))
  1081.                         {
  1082.                             TrackViewDeleteRangeSelection(Window->TrackView);
  1083.                         }
  1084.                     TrackWindowUpdateScrollBars(Window);
  1085.                     break;
  1086.                 case 13: /* carriage return brings up attribute dialog for the selected thing */
  1087.                     if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1088.                         || TrackViewIsASingleCommandSelected(Window->TrackView))
  1089.                         {
  1090.                             TrackViewEditSingleSelectionAttributes(Window->TrackView);
  1091.                         }
  1092.                     break;
  1093.                 case 3: /* show selection */
  1094.                     TrackWindowShowSelection(Window);
  1095.                     break;
  1096.                 case '<': /* transpose note down 1 step */
  1097.                     if ((TrackViewIsARangeSelected(Window->TrackView))
  1098.                         || TrackViewIsASingleNoteSelected(Window->TrackView))
  1099.                         {
  1100.                             TrackViewTransposeSelection(Window->TrackView,-1);
  1101.                         }
  1102.                     break;
  1103.                 case '>': /* transpose note up 1 step */
  1104.                     if ((TrackViewIsARangeSelected(Window->TrackView))
  1105.                         || TrackViewIsASingleNoteSelected(Window->TrackView))
  1106.                         {
  1107.                             TrackViewTransposeSelection(Window->TrackView,1);
  1108.                         }
  1109.                     break;
  1110.             }
  1111.     }
  1112.  
  1113.  
  1114. void                                        TrackWindowClose(TrackWindowRec* Window)
  1115.     {
  1116.         CheckPtrExistence(Window);
  1117.         DisposeTrackWindow(Window);
  1118.     }
  1119.  
  1120.  
  1121. void                                        TrackWindowUpdator(TrackWindowRec* Window)
  1122.     {
  1123.         OrdType                                XSize;
  1124.         OrdType                                YSize;
  1125.  
  1126.         CheckPtrExistence(Window);
  1127.         XSize = GetWindowWidth(Window->ScreenID);
  1128.         YSize = GetWindowHeight(Window->ScreenID);
  1129.         RedrawScrollBar(Window->HScroll);
  1130.         RedrawScrollBar(Window->VScroll);
  1131.         RedrawIconButton(Window->ArrowButton);
  1132.         RedrawIconButton(Window->CommandButton);
  1133.         RedrawIconButton(Window->SixtyFourthButton);
  1134.         RedrawIconButton(Window->ThirtySecondButton);
  1135.         RedrawIconButton(Window->SixteenthButton);
  1136.         RedrawIconButton(Window->EighthButton);
  1137.         RedrawIconButton(Window->QuarterButton);
  1138.         RedrawIconButton(Window->HalfButton);
  1139.         RedrawIconButton(Window->WholeButton);
  1140.         RedrawIconButton(Window->DoubleButton);
  1141.         RedrawIconButton(Window->QuadButton);
  1142.         RedrawIconButton(Window->SharpButton);
  1143.         RedrawIconButton(Window->FlatButton);
  1144.         RedrawIconButton(Window->NaturalButton);
  1145.         RedrawIconButton(Window->NoteVsRestButton);
  1146.         RedrawIconButton(Window->RestVsNoteButton);
  1147.         RedrawIconButton(Window->NoDotButton);
  1148.         RedrawIconButton(Window->YesDotButton);
  1149.         RedrawIconButton(Window->Div1Button);
  1150.         RedrawIconButton(Window->Div3Button);
  1151.         RedrawIconButton(Window->Div5Button);
  1152.         RedrawIconButton(Window->Div7Button);
  1153.         TrackViewRedrawAll(Window->TrackView);
  1154.         SetClipRect(Window->ScreenID,0,0,XSize,YSize);
  1155.         DrawLine(Window->ScreenID,eBlack,0,BUTTONSY + BUTTONHEIGHT - 1,XSize,0);
  1156.         DrawBitmap(Window->ScreenID,XSize - 15,YSize - 15,
  1157.             GetGrowIcon(Window->MyGenericWindow == GetCurrentWindowID()));
  1158.     }
  1159.  
  1160.  
  1161. void                                        TrackWindowMenuSetup(TrackWindowRec* Window)
  1162.     {
  1163.         CheckPtrExistence(Window);
  1164.         MainWindowEnableGlobalMenus(Window->MainWindow);
  1165.         ChangeItemName(mCloseFile,"Close Track Editor");
  1166.         EnableMenuItem(mCloseFile);
  1167.         ChangeItemName(mDeleteObject,"Delete Track");
  1168.         EnableMenuItem(mDeleteObject);
  1169.         TrackListEnableMenuItems(Window->TrackList);
  1170.         TrackListMenuItemCheckmarks(Window->TrackList,
  1171.             TrackObjectGetBackgroundList(Window->TrackObject));
  1172.         SetItemCheckmark(TrackObjectGetMenuItem(Window->TrackObject));
  1173.         EnableMenuItem(mEditTrackAttributes);
  1174.         SetItemCheckmark(Window->MyMenuItem);
  1175.  
  1176.         EnableMenuItem(mShowSelection);
  1177.  
  1178.         EnableMenuItem(mSelectAll);
  1179.         if (TrackViewIsThereInsertionPoint(Window->TrackView)
  1180.             || TrackViewIsARangeSelected(Window->TrackView))
  1181.             {
  1182.                 EnableMenuItem(mPaste);
  1183.                 ChangeItemName(mPaste,"Paste");
  1184.             }
  1185.         if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1186.             || TrackViewIsASingleCommandSelected(Window->TrackView))
  1187.             {
  1188.                 EnableMenuItem(mClear);
  1189.                 ChangeItemName(mClear,"Delete Note");
  1190.             }
  1191.         if (TrackViewIsARangeSelected(Window->TrackView))
  1192.             {
  1193.                 EnableMenuItem(mClear);
  1194.                 ChangeItemName(mClear,"Delete Selection");
  1195.                 EnableMenuItem(mCut);
  1196.                 ChangeItemName(mCut,"Cut Selection");
  1197.                 EnableMenuItem(mCopy);
  1198.                 ChangeItemName(mCopy,"Copy Selection");
  1199.             }
  1200.         if (TrackViewCanWeUndo(Window->TrackView))
  1201.             {
  1202.                 EnableMenuItem(mUndo);
  1203.                 ChangeItemName(mUndo,"Undo Track Edit");
  1204.             }
  1205.         if ((TrackViewIsARangeSelected(Window->TrackView))
  1206.             || TrackViewIsASingleNoteSelected(Window->TrackView))
  1207.             {
  1208.                 EnableMenuItem(mTransposeSelection);
  1209.             }
  1210.  
  1211.         EnableMenuItem(mPlayThisTrackFromHere);
  1212.         EnableMenuItem(mPlayAllTracksFromHere);
  1213.         Window->LastMenuOptionKeyDown = ((CheckModifiers() & eOptionKey) != 0);
  1214.         if (Window->LastMenuOptionKeyDown)
  1215.             {
  1216.                 ChangeItemName(mPlayThisTrackFromHere,"Play This Track To Disk");
  1217.                 ChangeItemName(mPlayAllTracksFromHere,"Play All Tracks To Disk");
  1218.             }
  1219.          else
  1220.             {
  1221.                 ChangeItemName(mPlayThisTrackFromHere,"Play This Track");
  1222.                 ChangeItemName(mPlayAllTracksFromHere,"Play All Tracks");
  1223.             }
  1224.  
  1225.         EnableMenuItem(mGotoMeasureBar);
  1226.     }
  1227.  
  1228.  
  1229. void                                        TrackWindowDoMenuCommand(TrackWindowRec* Window,
  1230.                                                     MenuItemType* MenuItem)
  1231.     {
  1232.         TrackObjectRec*                Track;
  1233.  
  1234.         CheckPtrExistence(Window);
  1235.         if (MainWindowDoGlobalMenuItem(Window->MainWindow,MenuItem))
  1236.             {
  1237.             }
  1238.         else if (MenuItem == mCloseFile)
  1239.             {
  1240.                 TrackWindowClose(Window);
  1241.             }
  1242.         else if (MenuItem == mDeleteObject)
  1243.             {
  1244.                 TrackListDeleteTrack(Window->TrackList,Window->TrackObject);
  1245.             }
  1246.         else if (NIL != (Track = TrackListLookupMenuItem(Window->TrackList,MenuItem)))
  1247.             {
  1248.                 ArrayRec*                            Backgrounded;
  1249.  
  1250.                 Backgrounded = TrackObjectGetBackgroundList(Window->TrackObject);
  1251.                 if (ArrayFindElement(Backgrounded,Track) >= 0)
  1252.                     {
  1253.                         /* item is in array -- remove it */
  1254.                         if (Window->TrackObject != Track)
  1255.                             {
  1256.                                 TrackObjectRemoveBackgroundObj(Window->TrackObject,Track);
  1257.                                 TrackObjectRemoveDependentView(Track,Window->TrackView);
  1258.                                 TrackViewRemoveBackgroundTrack(Window->TrackView,Track);
  1259.                             }
  1260.                     }
  1261.                  else
  1262.                     {
  1263.                         /* item is not in array -- add it */
  1264.                         if (Window->TrackObject != Track)
  1265.                             {
  1266.                                 /* our track needs to know that it has another track in background */
  1267.                                 if (!TrackObjectAddBackgroundObj(Window->TrackObject,Track))
  1268.                                     {
  1269.                                      AddTrackFailurePoint1:
  1270.                                         return;
  1271.                                     }
  1272.                                 /* the other track needs to know about our view so that */
  1273.                                 /* it can notify it about updates */
  1274.                                 if (!TrackObjectAddDependentView(Track,Window->TrackView))
  1275.                                     {
  1276.                                      AddTrackFailurePoint2:
  1277.                                         TrackObjectRemoveBackgroundObj(Window->TrackObject,Track);
  1278.                                         goto AddTrackFailurePoint1;
  1279.                                     }
  1280.                                 /* the view needs to know so it can add it to the scheduler */
  1281.                                 if (!TrackViewAddBackgroundTrack(Window->TrackView,Track))
  1282.                                     {
  1283.                                      AddTrackFailurePoint3:
  1284.                                         TrackObjectRemoveDependentView(Track,Window->TrackView);
  1285.                                         goto AddTrackFailurePoint2;
  1286.                                     }
  1287.                             }
  1288.                     }
  1289.                 TrackWindowUpdateScrollBars(Window);
  1290.             }
  1291.         else if (MenuItem == mEditTrackAttributes)
  1292.             {
  1293.                 TrackAttributeDialog(Window->TrackObject);
  1294.             }
  1295.         else if (MenuItem == mSelectAll)
  1296.             {
  1297.                 TrackViewSelectAll(Window->TrackView);
  1298.             }
  1299.         else if (MenuItem == mPaste)
  1300.             {
  1301.                 TrackViewAttemptPaste(Window->TrackView);
  1302.                 TrackWindowUpdateScrollBars(Window);
  1303.             }
  1304.         else if (MenuItem == mClear)
  1305.             {
  1306.                 if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1307.                     || TrackViewIsASingleCommandSelected(Window->TrackView))
  1308.                     {
  1309.                         TrackViewDeleteSingleNoteOrCommand(Window->TrackView);
  1310.                     }
  1311.                 else if (TrackViewIsARangeSelected(Window->TrackView))
  1312.                     {
  1313.                         TrackViewDeleteRangeSelection(Window->TrackView);
  1314.                     }
  1315.                 TrackWindowShowSelection(Window);
  1316.             }
  1317.         else if (MenuItem == mCut)
  1318.             {
  1319.                 TrackViewCutRangeSelection(Window->TrackView);
  1320.                 TrackWindowShowSelection(Window);
  1321.             }
  1322.         else if (MenuItem == mCopy)
  1323.             {
  1324.                 TrackViewCopyRangeSelection(Window->TrackView);
  1325.             }
  1326.         else if (MenuItem == mUndo)
  1327.             {
  1328.                 TrackViewUndo(Window->TrackView);
  1329.                 TrackWindowShowSelection(Window);
  1330.             }
  1331.         else if (MenuItem == mPlayThisTrackFromHere)
  1332.             {
  1333.                 long                            StartIndex;
  1334.                 ArrayRec*                    TrackList;
  1335.  
  1336.                 if (TrackViewIsARangeSelected(Window->TrackView))
  1337.                     {
  1338.                         StartIndex = TrackViewGetRangeStart(Window->TrackView);
  1339.                     }
  1340.                 else if (TrackViewIsThereInsertionPoint(Window->TrackView))
  1341.                     {
  1342.                         StartIndex = TrackViewGetInsertionPointIndex(Window->TrackView);
  1343.                     }
  1344.                 else if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1345.                     || TrackViewIsASingleCommandSelected(Window->TrackView))
  1346.                     {
  1347.                         StartIndex = TrackViewGetSingleNoteSelectionFrameNumber(Window->TrackView);
  1348.                     }
  1349.                 else
  1350.                     {
  1351.                         StartIndex = 0; /* default to the beginning for other selections */
  1352.                     }
  1353.                 TrackList = NewArray();
  1354.                 if (TrackList == NIL)
  1355.                     {
  1356.                      PlaySingleFailurePoint1:
  1357.                         AlertHalt("There is not enough memory available to play the track.",NIL);
  1358.                         return;
  1359.                     }
  1360.                 if (!ArrayAppendElement(TrackList,Window->TrackObject))
  1361.                     {
  1362.                      PlaySingleFailurePoint2:
  1363.                         DisposeArray(TrackList);
  1364.                         goto PlaySingleFailurePoint1;
  1365.                     }
  1366.                 if (!Window->LastMenuOptionKeyDown)
  1367.                     {
  1368.                         SynthToSoundDevice(Window->MainWindow,TrackList,Window->TrackObject,
  1369.                             StartIndex,MainWindowGetSamplingRate(Window->MainWindow),
  1370.                             MainWindowGetEnvelopeRate(Window->MainWindow),
  1371.                             MainWindowGetStereo(Window->MainWindow),
  1372.                             Double2LargeBCD(MainWindowGetBeatsPerMinute(Window->MainWindow)),
  1373.                             Double2LargeBCD(MainWindowGetVolumeScaling(Window->MainWindow)),
  1374.                             MainWindowGetInterpolationOverTime(Window->MainWindow),
  1375.                             MainWindowGetInterpolationAcrossWaves(Window->MainWindow),
  1376.                             Double2LargeBCD(MainWindowGetScanningGap(Window->MainWindow)),
  1377.                             MainWindowGetOutputNumBits(Window->MainWindow),
  1378.                             Double2LargeBCD(MainWindowGetBufferDuration(Window->MainWindow)),False);
  1379.                     }
  1380.                  else
  1381.                     {
  1382.                         SynthToAIFFFile(Window->MainWindow,TrackList,Window->TrackObject,
  1383.                             StartIndex,MainWindowGetSamplingRate(Window->MainWindow),
  1384.                             MainWindowGetEnvelopeRate(Window->MainWindow),
  1385.                             MainWindowGetStereo(Window->MainWindow),
  1386.                             Double2LargeBCD(MainWindowGetBeatsPerMinute(Window->MainWindow)),
  1387.                             Double2LargeBCD(MainWindowGetVolumeScaling(Window->MainWindow)),
  1388.                             MainWindowGetInterpolationOverTime(Window->MainWindow),
  1389.                             MainWindowGetInterpolationAcrossWaves(Window->MainWindow),
  1390.                             Double2LargeBCD(MainWindowGetScanningGap(Window->MainWindow)),
  1391.                             MainWindowGetOutputNumBits(Window->MainWindow),False);
  1392.                     }
  1393.                 DisposeArray(TrackList);
  1394.             }
  1395.         else if (MenuItem == mPlayAllTracksFromHere)
  1396.             {
  1397.                 long                            StartIndex;
  1398.                 ArrayRec*                    TrackList;
  1399.                 long                            TrackListScan;
  1400.  
  1401.                 if (TrackViewIsARangeSelected(Window->TrackView))
  1402.                     {
  1403.                         StartIndex = TrackViewGetRangeStart(Window->TrackView);
  1404.                     }
  1405.                 else if (TrackViewIsThereInsertionPoint(Window->TrackView))
  1406.                     {
  1407.                         StartIndex = TrackViewGetInsertionPointIndex(Window->TrackView);
  1408.                     }
  1409.                 else if (TrackViewIsASingleNoteSelected(Window->TrackView)
  1410.                     || TrackViewIsASingleCommandSelected(Window->TrackView))
  1411.                     {
  1412.                         StartIndex = TrackViewGetSingleNoteSelectionFrameNumber(Window->TrackView);
  1413.                     }
  1414.                 else
  1415.                     {
  1416.                         StartIndex = 0; /* default to the beginning for other selections */
  1417.                     }
  1418.                 TrackList = TrackListGetListOfAllTracks(Window->TrackList);
  1419.                 if (TrackList == NIL)
  1420.                     {
  1421.                         AlertHalt("There is not enough memory available to play the track.",NIL);
  1422.                         return;
  1423.                     }
  1424.                 TrackListScan = 0;
  1425.                 /* keep only the tracks that are marked to be played */
  1426.                 while (TrackListScan < ArrayGetLength(TrackList))
  1427.                     {
  1428.                         TrackObjectRec*            MaybeTrack;
  1429.  
  1430.                         MaybeTrack = (TrackObjectRec*)ArrayGetElement(TrackList,TrackListScan);
  1431.                         CheckPtrExistence(MaybeTrack);
  1432.                         if ((MaybeTrack != Window->TrackObject) /* we MUST keep the current track! */
  1433.                             && !TrackObjectShouldItBePlayed(MaybeTrack))
  1434.                             {
  1435.                                 ArrayDeleteElement(TrackList,TrackListScan);
  1436.                             }
  1437.                          else
  1438.                             {
  1439.                                 TrackListScan += 1;
  1440.                             }
  1441.                     }
  1442.                 if (!Window->LastMenuOptionKeyDown)
  1443.                     {
  1444.                         SynthToSoundDevice(Window->MainWindow,TrackList,Window->TrackObject,
  1445.                             StartIndex,MainWindowGetSamplingRate(Window->MainWindow),
  1446.                             MainWindowGetEnvelopeRate(Window->MainWindow),
  1447.                             MainWindowGetStereo(Window->MainWindow),
  1448.                             Double2LargeBCD(MainWindowGetBeatsPerMinute(Window->MainWindow)),
  1449.                             Double2LargeBCD(MainWindowGetVolumeScaling(Window->MainWindow)),
  1450.                             MainWindowGetInterpolationOverTime(Window->MainWindow),
  1451.                             MainWindowGetInterpolationAcrossWaves(Window->MainWindow),
  1452.                             Double2LargeBCD(MainWindowGetScanningGap(Window->MainWindow)),
  1453.                             MainWindowGetOutputNumBits(Window->MainWindow),
  1454.                             Double2LargeBCD(MainWindowGetBufferDuration(Window->MainWindow)),False);
  1455.                     }
  1456.                  else
  1457.                     {
  1458.                         SynthToAIFFFile(Window->MainWindow,TrackList,Window->TrackObject,
  1459.                             StartIndex,MainWindowGetSamplingRate(Window->MainWindow),
  1460.                             MainWindowGetEnvelopeRate(Window->MainWindow),
  1461.                             MainWindowGetStereo(Window->MainWindow),
  1462.                             Double2LargeBCD(MainWindowGetBeatsPerMinute(Window->MainWindow)),
  1463.                             Double2LargeBCD(MainWindowGetVolumeScaling(Window->MainWindow)),
  1464.                             MainWindowGetInterpolationOverTime(Window->MainWindow),
  1465.                             MainWindowGetInterpolationAcrossWaves(Window->MainWindow),
  1466.                             Double2LargeBCD(MainWindowGetScanningGap(Window->MainWindow)),
  1467.                             MainWindowGetOutputNumBits(Window->MainWindow),False);
  1468.                     }
  1469.                 DisposeArray(TrackList);
  1470.             }
  1471.         else if (MenuItem == mShowSelection)
  1472.             {
  1473.                 TrackWindowShowSelection(Window);
  1474.             }
  1475.         else if (MenuItem == mTransposeSelection)
  1476.             {
  1477.                 long                        Transpose;
  1478.  
  1479.                 Transpose = DoNumberDialog("Transpose half-steps:",0,mCut,mPaste,mCopy,
  1480.                     mUndo,mSelectAll,mClear);
  1481.                 if (Transpose != 0)
  1482.                     {
  1483.                         TrackViewTransposeSelection(Window->TrackView,Transpose);
  1484.                     }
  1485.             }
  1486.         else if (MenuItem == mGotoMeasureBar)
  1487.             {
  1488.                 long                        NewMeasure;
  1489.  
  1490.                 NewMeasure = DoNumberDialog("Go To Measure:",0,mCut,mPaste,mCopy,
  1491.                     mUndo,mSelectAll,mClear);
  1492.                 if (NewMeasure != 0)
  1493.                     {
  1494.                         TrackViewShowMeasure(Window->TrackView,NewMeasure);
  1495.                         TrackWindowUpdateScrollBars(Window);
  1496.                     }
  1497.             }
  1498.         else
  1499.             {
  1500.                 EXECUTE(PRERR(ForceAbort,"TrackWindowDoMenuCommand:  unknown menu command"));
  1501.             }
  1502.     }
  1503.  
  1504.  
  1505. void                                        TrackWindowUpdateVScrollBar(TrackWindowRec* Window)
  1506.     {
  1507.         CheckPtrExistence(Window);
  1508.         SetMaxScrollIndex(Window->VScroll,
  1509.             TrackViewGetVerticalDegreesOfFreedom(Window->TrackView));
  1510.         SetScrollIndex(Window->VScroll,TrackViewGetVerticalOffset(Window->TrackView));
  1511.         RedrawScrollBar(Window->VScroll);
  1512.     }
  1513.  
  1514.  
  1515. /* update the positioning of the horizontal scroll bar and redraw */
  1516. void                                        TrackWindowUpdateHScrollBar(TrackWindowRec* Window)
  1517.     {
  1518.         CheckPtrExistence(Window);
  1519.         SetMaxScrollIndex(Window->HScroll,
  1520.             TrackViewGetHorizontalDegreesOfFreedom(Window->TrackView));
  1521.         SetScrollIndex(Window->HScroll,TrackViewGetHorizontalOffset(Window->TrackView));
  1522.         RedrawScrollBar(Window->HScroll);
  1523.     }
  1524.  
  1525.  
  1526. static void                            TrackWindowVScrollHook(long Parameter, ScrollType How,
  1527.                                                     TrackWindowRec* Window)
  1528.     {
  1529.         long                                    NewPosition;
  1530.  
  1531.         CheckPtrExistence(Window);
  1532.         switch (How)
  1533.             {
  1534.                 case eScrollToPosition:
  1535.                     NewPosition = Parameter;
  1536.                     break;
  1537.                 case eScrollPageMinus:
  1538.                     NewPosition = TrackViewGetVerticalOffset(Window->TrackView)
  1539.                         - (7 * GetTrackViewHeight(Window->TrackView)) / 8;
  1540.                     break;
  1541.                 case eScrollPagePlus:
  1542.                     NewPosition = TrackViewGetVerticalOffset(Window->TrackView)
  1543.                         + (7 * GetTrackViewHeight(Window->TrackView)) / 8;
  1544.                     break;
  1545.                 case eScrollLineMinus:
  1546.                     NewPosition = TrackViewGetVerticalOffset(Window->TrackView)
  1547.                         - (1 * GetTrackViewHeight(Window->TrackView)) / 8;
  1548.                     break;
  1549.                 case eScrollLinePlus:
  1550.                     NewPosition = TrackViewGetVerticalOffset(Window->TrackView)
  1551.                         + (1 * GetTrackViewHeight(Window->TrackView)) / 8;
  1552.                     break;
  1553.                 default:
  1554.                     EXECUTE(PRERR(AllowResume,"TrackWindowVScrollHook:  Unknown scroll opcode"));
  1555.                     break;
  1556.             }
  1557.         TrackViewSetNewVerticalOffset(Window->TrackView,NewPosition);
  1558.         TrackWindowUpdateVScrollBar(Window);
  1559.     }
  1560.  
  1561.  
  1562. static void                            TrackWindowHScrollHook(long Parameter, ScrollType How,
  1563.                                                     TrackWindowRec* Window)
  1564.     {
  1565.         long                                    NewPosition;
  1566.  
  1567.         CheckPtrExistence(Window);
  1568.         switch (How)
  1569.             {
  1570.                 case eScrollToPosition:
  1571.                     NewPosition = Parameter;
  1572.                     break;
  1573.                 case eScrollPageMinus:
  1574.                     NewPosition = TrackViewGetHorizontalOffset(Window->TrackView)
  1575.                         - (7 * GetTrackViewWidth(Window->TrackView)) / 8;
  1576.                     break;
  1577.                 case eScrollPagePlus:
  1578.                     NewPosition = TrackViewGetHorizontalOffset(Window->TrackView)
  1579.                         + (7 * GetTrackViewWidth(Window->TrackView)) / 8;
  1580.                     break;
  1581.                 case eScrollLineMinus:
  1582.                     NewPosition = TrackViewGetHorizontalOffset(Window->TrackView)
  1583.                         - (1 * GetTrackViewWidth(Window->TrackView)) / 8;
  1584.                     break;
  1585.                 case eScrollLinePlus:
  1586.                     NewPosition = TrackViewGetHorizontalOffset(Window->TrackView)
  1587.                         + (1 * GetTrackViewWidth(Window->TrackView)) / 8;
  1588.                     break;
  1589.                 default:
  1590.                     EXECUTE(PRERR(AllowResume,"TrackWindowHScrollHook:  Unknown scroll opcode"));
  1591.                     break;
  1592.             }
  1593.         TrackViewSetNewHorizontalOffset(Window->TrackView,NewPosition);
  1594.         TrackWindowUpdateHScrollBar(Window);
  1595.     }
  1596.  
  1597.  
  1598. /* reset the state of the note attribute buttons according to the attribute flags */
  1599. void                                        TrackWindowResetButtons(TrackWindowRec* Window)
  1600.     {
  1601.         CheckPtrExistence(Window);
  1602.         if (!Window->NoteReady)
  1603.             {
  1604.                 SetIconButtonState(Window->ArrowButton,True);
  1605.                 SetIconButtonState(Window->CommandButton,False);
  1606.              NoteButtonsOffPoint:
  1607.                 SetIconButtonState(Window->SixtyFourthButton,False);
  1608.                 SetIconButtonState(Window->ThirtySecondButton,False);
  1609.                 SetIconButtonState(Window->SixteenthButton,False);
  1610.                 SetIconButtonState(Window->EighthButton,False);
  1611.                 SetIconButtonState(Window->QuarterButton,False);
  1612.                 SetIconButtonState(Window->HalfButton,False);
  1613.                 SetIconButtonState(Window->WholeButton,False);
  1614.                 SetIconButtonState(Window->DoubleButton,False);
  1615.                 SetIconButtonState(Window->QuadButton,False);
  1616.                 SetIconButtonState(Window->SharpButton,False);
  1617.                 SetIconButtonState(Window->FlatButton,False);
  1618.                 SetIconButtonState(Window->NaturalButton,False);
  1619.                 SetIconButtonState(Window->NoteVsRestButton,False);
  1620.                 SetIconButtonState(Window->RestVsNoteButton,False);
  1621.                 SetIconButtonState(Window->NoDotButton,False);
  1622.                 SetIconButtonState(Window->YesDotButton,False);
  1623.                 SetIconButtonState(Window->Div1Button,False);
  1624.                 SetIconButtonState(Window->Div3Button,False);
  1625.                 SetIconButtonState(Window->Div5Button,False);
  1626.                 SetIconButtonState(Window->Div7Button,False);
  1627.             }
  1628.          else
  1629.             {
  1630.                 SetIconButtonState(Window->ArrowButton,False);
  1631.                 if ((Window->NoteState & eCommandFlag) != 0)
  1632.                     {
  1633.                         SetIconButtonState(Window->CommandButton,True);
  1634.                         goto NoteButtonsOffPoint;
  1635.                     }
  1636.                  else
  1637.                     {
  1638.                         SetIconButtonState(Window->CommandButton,False);
  1639.  
  1640.                         SetIconButtonState(Window->SixtyFourthButton,
  1641.                             (Window->NoteState & eDurationMask) == e64thNote);
  1642.                         SetIconButtonState(Window->ThirtySecondButton,
  1643.                             (Window->NoteState & eDurationMask) == e32ndNote);
  1644.                         SetIconButtonState(Window->SixteenthButton,
  1645.                             (Window->NoteState & eDurationMask) == e16thNote);
  1646.                         SetIconButtonState(Window->EighthButton,
  1647.                             (Window->NoteState & eDurationMask) == e8thNote);
  1648.                         SetIconButtonState(Window->QuarterButton,
  1649.                             (Window->NoteState & eDurationMask) == e4thNote);
  1650.                         SetIconButtonState(Window->HalfButton,
  1651.                             (Window->NoteState & eDurationMask) == e2ndNote);
  1652.                         SetIconButtonState(Window->WholeButton,
  1653.                             (Window->NoteState & eDurationMask) == eWholeNote);
  1654.                         SetIconButtonState(Window->DoubleButton,
  1655.                             (Window->NoteState & eDurationMask) == eDoubleNote);
  1656.                         SetIconButtonState(Window->QuadButton,
  1657.                             (Window->NoteState & eDurationMask) == eQuadNote);
  1658.  
  1659.                         SetIconButtonState(Window->SharpButton,
  1660.                             (Window->NoteState & eSharpModifier) != 0);
  1661.                         SetIconButtonState(Window->FlatButton,
  1662.                             (Window->NoteState & eFlatModifier) != 0);
  1663.                         SetIconButtonState(Window->NaturalButton,
  1664.                             (Window->NoteState & (eFlatModifier | eSharpModifier)) == 0);
  1665.  
  1666.                         SetIconButtonState(Window->NoteVsRestButton,
  1667.                             (Window->NoteState & eRestModifier) == 0);
  1668.                         SetIconButtonState(Window->RestVsNoteButton,
  1669.                             (Window->NoteState & eRestModifier) != 0);
  1670.  
  1671.                         SetIconButtonState(Window->NoDotButton,
  1672.                             (Window->NoteState & eDotModifier) == 0);
  1673.                         SetIconButtonState(Window->YesDotButton,
  1674.                             (Window->NoteState & eDotModifier) != 0);
  1675.  
  1676.                         SetIconButtonState(Window->Div1Button,
  1677.                             (Window->NoteState & eDivisionMask) == eDiv1Modifier);
  1678.                         SetIconButtonState(Window->Div3Button,
  1679.                             (Window->NoteState & eDivisionMask) == eDiv3Modifier);
  1680.                         SetIconButtonState(Window->Div5Button,
  1681.                             (Window->NoteState & eDivisionMask) == eDiv5Modifier);
  1682.                         SetIconButtonState(Window->Div7Button,
  1683.                             (Window->NoteState & eDivisionMask) == eDiv7Modifier);
  1684.                     }
  1685.             }
  1686.     }
  1687.  
  1688.  
  1689. /* the name of the file has changed, so update the title bar of the window.  the */
  1690. /* NewFilename is a non-null-terminated string.  the caller is responsible for */
  1691. /* disposing of it */
  1692. void                                        TrackWindowGlobalNameChange(TrackWindowRec* Window,
  1693.                                                     char* NewFilename)
  1694.     {
  1695.         char*                                    LocalNameCopy;
  1696.  
  1697.         CheckPtrExistence(Window);
  1698.         CheckPtrExistence(NewFilename);
  1699.         LocalNameCopy = TrackObjectGetNameCopy(Window->TrackObject);
  1700.         if (LocalNameCopy != NIL)
  1701.             {
  1702.                 char*                            SeparatorString;
  1703.  
  1704.                 SeparatorString = StringToBlockCopy(":  ");
  1705.                 if (SeparatorString != NIL)
  1706.                     {
  1707.                         char*                            LeftHalfOfString;
  1708.  
  1709.                         LeftHalfOfString = ConcatBlockCopy(NewFilename,SeparatorString);
  1710.                         if (LeftHalfOfString != NIL)
  1711.                             {
  1712.                                 char*                            TotalString;
  1713.  
  1714.                                 TotalString = ConcatBlockCopy(LeftHalfOfString,LocalNameCopy);
  1715.                                 if (TotalString != NIL)
  1716.                                     {
  1717.                                         char*                            NullTerminatedString;
  1718.  
  1719.                                         NullTerminatedString = BlockToStringCopy(TotalString);
  1720.                                         if (NullTerminatedString != NIL)
  1721.                                             {
  1722.                                                 SetWindowName(Window->ScreenID,NullTerminatedString);
  1723.                                                 ChangeItemName(Window->MyMenuItem,NullTerminatedString);
  1724.                                                 ReleasePtr(NullTerminatedString);
  1725.                                             }
  1726.                                         ReleasePtr(TotalString);
  1727.                                     }
  1728.                                 ReleasePtr(LeftHalfOfString);
  1729.                             }
  1730.                         ReleasePtr(SeparatorString);
  1731.                     }
  1732.                 ReleasePtr(LocalNameCopy);
  1733.             }
  1734.     }
  1735.  
  1736.  
  1737. /* reset the title bar even if the filename hasn't changed */
  1738. void                                        TrackWindowResetTitlebar(TrackWindowRec* Window)
  1739.     {
  1740.         char*                                    DocumentName;
  1741.  
  1742.         CheckPtrExistence(Window);
  1743.         DocumentName = GetCopyOfDocumentName(Window->MainWindow);
  1744.         if (DocumentName != NIL)
  1745.             {
  1746.                 TrackWindowGlobalNameChange(Window,DocumentName);
  1747.                 ReleasePtr(DocumentName);
  1748.             }
  1749.     }
  1750.  
  1751.  
  1752. /* update both scrollbars */
  1753. void                                        TrackWindowUpdateScrollBars(TrackWindowRec* Window)
  1754.     {
  1755.         CheckPtrExistence(Window);
  1756.         TrackWindowUpdateVScrollBar(Window);
  1757.         TrackWindowUpdateHScrollBar(Window);
  1758.     }
  1759.  
  1760.  
  1761. /* show the current selection in the window */
  1762. void                                        TrackWindowShowSelection(TrackWindowRec* Window)
  1763.     {
  1764.         CheckPtrExistence(Window);
  1765.         TrackViewShowSelection(Window->TrackView);
  1766.         TrackWindowUpdateScrollBars(Window);
  1767.     }
  1768.